﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Principal;
using System.Web;

namespace common
{
    public static class UserFind
    {
        public static string UserName
        {
            get
            {
                string full = FullUserName;
                if (full.IndexOf(@"\") > 0)
                {
                    full = full.Substring(full.IndexOf(@"\") + 1);
                }
                return full;
            }
        }
        public static string FullUserName
        {
            get
            {                
                string ret = "";
                HttpContext htc = HttpContext.Current;
                if (htc != null && htc.User != null && htc.User.Identity != null)
                {
                    ret = htc.User.Identity.Name;
                }
                if (string.IsNullOrWhiteSpace(ret))
                {
                    ret = Environment.UserDomainName + @"\" + Environment.UserName;
                }
                if (string.IsNullOrWhiteSpace(ret))
                {
                    ret = WindowsIdentity.GetCurrent().Name;
                }                
                return ret;

            }
        }
    }
}
